package application;

import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;

public class Location {
	
	public String Name;
	public String ShortName;
	public String Country;
	public String City;
	public String Address;
	public String Map;
	public String Description;
	public String Web;
	public String Image;
	
	public Location(String name, String shortName, String country,
			String city, String address, String map, String description,
			String web, String image) {
		super();
		this.Name = name;
		this.ShortName = shortName;
		this.Country = country;
		this.City = city;
		this.Address = address;
		this.Map = map;
		this.Description = description;
		this.Web = web;
		this.Image = image;
	}

	public Location() {
		super();
		this.Name = "new location";
		this.ShortName = null;
		this.Country = null;
		this.City = null;
		this.Address = null;
		this.Map = null;
		this.Description = "this is a new location";
		this.Web = null;
		this.Image = null;
	}
	
	public void dbCreateLocation (String dbFile){
		ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded
		        .newConfiguration(), dbFile);
		
		try{

	        		db.store(this);


		}
		finally{
			db.close();
		}
	}
	
	public void dbEditLocation (String dbFile, Location c){
		ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded
		        .newConfiguration(), dbFile);
		
		try{
			try{
				ObjectSet<Location> result = db
		        .queryByExample(Location.this);
				Location found = (Location) result.next();
				db.delete(found);
				this.setAddress(c.getAddress());
				this.setCity(c.getCity());
				this.setCountry(c.getCountry());
				this.setMap(c.getMap());
				this.setDescription(c.getDescription());
				this.setImage(c.getImage());
				this.setName(c.getName());
				this.setShortName(c.getShortName());
				this.setWeb(c.getWeb());
				db.store(this);
				
			}
			catch(IllegalStateException e){
				
			}

		}
		finally{
			db.close();
		}
	}
	
	public void dbDeleteLocationr (String dbFile){
		ObjectContainer db = Db4oEmbedded.openFile(Db4oEmbedded
		        .newConfiguration(), dbFile);
		
		try{
			try{
				ObjectSet<Location> result = db
		        .queryByExample(Location.this);
				Location found = (Location) result.next();
				db.delete(found);
			}
			catch(IllegalStateException e){
				
			}

		}
		finally{
			db.close();
		}
	}
	

	public String toString() {
		return Name;
	}

	public String getName() {
		return Name;
	}

	public String getShortName() {
		return ShortName;
	}

	public String getCountry() {
		return Country;
	}

	public String getCity() {
		return City;
	}

	public String getAddress() {
		return Address;
	}

	public String getMap() {
		return Map;
	}

	public String getDescription() {
		return Description;
	}

	public String getWeb() {
		return Web;
	}

	public String getImage() {
		return Image;
	}

	public void setName(String name) {
		Name = name;
	}

	public void setShortName(String shortName) {
		ShortName = shortName;
	}

	public void setCountry(String country) {
		Country = country;
	}

	public void setCity(String city) {
		City = city;
	}

	public void setAddress(String address) {
		Address = address;
	}

	public void setMap(String map) {
		Map = map;
	}

	public void setDescription(String description) {
		Description = description;
	}

	public void setWeb(String web) {
		Web = web;
	}

	public void setImage(String image) {
		Image = image;
	}

	
	
	
	
	
	

}
